package com.jxc.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONObject;

import com.jxc.dao.TreeDAO;
import com.jxc.pojo.TreeTable;

/**
 * @包名   com.jxc.web
 * @文件名 OpTable.java
 * @作者   mopzyqing
 * @创建日期 Jul 21, 2010
 * @版本 V 1.0
 */
public class OpTableAction {

	@Resource private TreeDAO treeImpl;
	
	private int limit;  
	private int start;
	private int roleID;
	private int nodeId;
	private List root = new ArrayList();
	private int totalProperty;
	private String newOpString;
	
	public String tableDate(){
		
		//treeImpl.getOpByMenu(nodeId,start,limit);
		List<Object[]> list = treeImpl.getOpByMenuTable(roleID,nodeId,start,limit);
		for(Object[] object : list){
			
			TreeTable treeTable = new TreeTable();
			treeTable.setRole_id(Integer.valueOf(object[0].toString()));
			treeTable.setId(Integer.valueOf(object[1].toString()));
			treeTable.setOp_name(object[2].toString());
			root.add(treeTable);
		}
		totalProperty = 10;
		return "success";
	}
	public void saveOrUpdate(){

		JSONObject opJson = JSONObject.fromObject(newOpString);
		int nodeId = Integer.valueOf(opJson.getString("nodeId"));
		int role_id = Integer.valueOf(opJson.getString("role_id"));
		String opArray[] = opJson.getString("op_id").trim().split(",");
		//1.删除关于角色的所有权限   2.保存所有全县
		treeImpl.deleteMenuSubByOrderby(role_id,nodeId);
		treeImpl.saveTbPermissionRole(opArray,role_id);
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getRoleID() {
		return roleID;
	}
	public void setRoleID(int roleID) {
		this.roleID = roleID;
	}
	public int getNodeId() {
		return nodeId;
	}
	public void setNodeId(int nodeId) {
		this.nodeId = nodeId;
	}
	public List getRoot() {
		return root;
	}
	public void setRoot(List root) {
		this.root = root;
	}
	public int getTotalProperty() {
		return totalProperty;
	}
	public void setTotalProperty(int totalProperty) {
		this.totalProperty = totalProperty;
	}
	public String getNewOpString() {
		return newOpString;
	}
	public void setNewOpString(String newOpString) {
		this.newOpString = newOpString;
	}
}
